package lib.self.ex.decor;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import lib.self.R;
import lib.self.ex.ParamsEx;
import lib.self.ex.interfaces.OnRetryClickListener;

/**
 * description: 错误失败的View
 * author: Steven Xiao
 * date: 2017/5/2
 */
public class FailureView extends RelativeLayout implements OnClickListener {
    private OnRetryClickListener mOnRetryClickListener;
    private View mFailureView;

    public FailureView(Context context) {
        super(context);
        init();
    }

    public FailureView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public FailureView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        if (ParamsEx.getErrorViewId() != 0) {
            mFailureView = inflate(getContext(), ParamsEx.getErrorViewId(), null);
        } else {
            mFailureView = inflate(getContext(), R.layout.view_failure_default, null);
        }
        setOnClickListener(this);
        addView(mFailureView, LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }

    public void setOnRetryClickListener(OnRetryClickListener onRetryClickListener) {
        this.mOnRetryClickListener = onRetryClickListener;
    }

    @Override
    public void onClick(View v) {
        if (mOnRetryClickListener != null) {
            mOnRetryClickListener.onRetryClick();
        }
    }
}
